package top.goldenyear.porpoise.framework.web.core.generator.dialect.impl;

import cn.hutool.v7.core.text.StrUtil;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author airhead
 */
public class OracleDialect extends BaseJdbcDialect {
  @Override
  public ResultSet getTablesResultSet(
      DatabaseMetaData dbMeta, Connection conn, String schema, String[] types) throws SQLException {
    return dbMeta.getTables(
        conn.getCatalog(), StrUtil.isNotBlank(schema) ? schema : dbMeta.getUserName(), null, types);
  }

  @Override
  public String forBuildColumnsSql(String schema, String tableName) {
    return "SELECT * FROM \""
        + (StrUtil.isNotBlank(schema) ? schema + "\".\"" : "")
        + tableName
        + "\" WHERE rownum < 1";
  }
}
